package com.mask.im.sdk.config;

import com.mask.im.sdk.listener.RedisMsgListenerProcessor;
import com.mask.im.sdk.service.MessagePushService;
import com.mask.im.sdk.service.impl.MessageKafkaPushServiceImpl;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * Redis消息自动配置
 *
 * @author jian
 */
@Configuration
@ConditionalOnProperty(prefix = "redis.msg", name = "enabled", havingValue = "true", matchIfMissing = true)
public class RedisMessageAutoConfiguration {

    /**
     * 配置消息推送服务（主要实现）
     */
    @Bean
    @ConditionalOnMissingBean(MessagePushService.class)
    public MessagePushService messagePushService() {
        return new MessageKafkaPushServiceImpl();
    }

    /**
     * 配置Redis消息监听器处理器
     * 注意：RedisMsgListenerProcessor已使用@Component自动注册
     * 如果需要自定义配置，可以在这里进行
     */
    // RedisMsgListenerProcessor已通过@Component自动注册，无需手动创建Bean
    // 如果需要延迟初始化或特殊配置，可以取消下面的注释
    /*
    @Bean
    @ConditionalOnMissingBean(RedisMsgListenerProcessor.class)
    public RedisMsgListenerProcessor redisMsgListenerProcessor() {
        return new RedisMsgListenerProcessor();
    }
    */

}
